﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

namespace Client
{
    public class ImageExConverter : System.Windows.Data.IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            System.Windows.Media.Imaging.BitmapSource r = null;

            if (value == null)
            {
                return r;
            }

            if ((value is ViewModels.ImageEx) == false)
            {
                return r;
            }

            ViewModels.ImageEx model = value as ViewModels.ImageEx;

            using (var bitmap = new System.Drawing.Bitmap(model.FileInfo.FullName))
            {
                r = Util.Drawing.DrawingUtils.Bitmap2BitmapSource(bitmap);
                bitmap.Dispose();
            }

            return r;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
